using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Slobby.Client.UI.Controls {
    public partial class LoginPanel : UserControl {

        public event EventHandler<LogInEventArgs> LogInClicked;

        public LoginPanel() {
            InitializeComponent();
        }

        private string UserName {
            get {
                return username.Text.Trim();
            }
        }

        private bool ValidateInput() {
            if (UserName.Length == 0) {
                StatusMessage = "Please enter a name";
                return false;
            }
            return true;
        }

        private void SignIn_Click(object sender, EventArgs e) {
            if (ValidateInput()) {
                LogInEventArgs args = new LogInEventArgs(username.Text, password.Text);
                if (LogInClicked != null)
                    LogInClicked(this, args);
            }
        }

        public void ShowConnecting () {
            disablerPanel.Enabled = false;
            StatusMessage = "Connecting...";
        }

        public void HideConnecting() {
            disablerPanel.Enabled = true;
            StatusMessage = string.Empty;
        }

        public string StatusMessage {
            set {
                messageLabel.Text = value;
            }
        }

        private void TextFieldsKeydown(object sender, KeyEventArgs e) {
            if (e.KeyCode == Keys.Enter) {
                SignIn.PerformClick();
                e.SuppressKeyPress = true;
            }
        }
    }
}
